Running the Amazon S3 Personal File Store Sample

This Amazon S3 Personal File Store sample is fully detailed in the Mobile Credential Management article. The sample demonstrates how to customize the token vending machine to give application users specific and constrained permissions to an Amazon S3 bucket. Each application user will get a "folder" of an Amazon S3 bucket as specified by the modified policy. This README details all the steps necessary to get the sample fully running:

  1. Create an Amazon S3 bucket to use for the sample.
  2. Customize and build the token vending machine specific for this sample.
    Note: To build the token vending machine, you will need access to Ant and Java on your machine. The following steps need to be excuted from the command line:
  3. Deploy the token vending machine to AWS Elastic Beanstalk.
  4. Run the sample iOS or Android application.

TokenVendingMachinePolicy.json

You will need to update the default policy. Replace the occurrences of __BUCKET_NAME__ to an Amazon S3 bucket you created for this application. Do not modify the __USERNAME__ strings as those will be automatically updated by the token vending machine.

{"Statement":
    [
        {"Effect":"Allow","Action":["s3:PutObject","s3:GetObject","s3:DeleteObject"],"Resource":"arn:aws:s3:::__BUCKET_NAME__/__USERNAME__/*"},
        {"Effect":"Allow","Action":"s3:ListBucket","Resource":"arn:aws:s3:::__BUCKET_NAME__","Condition":{"StringLike":{"s3:prefix":"__USERNAME__/"}}},
        {"Effect":"Deny","Action":["iam:*", "sts:*", "sdb:*"],"Resource":"*"}
    ]
}

If you used my_s3_bucket as the bucket name for the substitution, your policy would result in the following:

{"Statement":
    [
        {"Effect":"Allow","Action":["s3:PutObject","s3:GetObject","s3:DeleteObject"],"Resource":"arn:aws:s3:::my_s3_bucket/__USERNAME__/*"},
        {"Effect":"Allow","Action":"s3:ListBucket","Resource":"arn:aws:s3:::my_s3_bucket","Condition":{"StringLike":{"s3:prefix":"__USERNAME__/"}}},
        {"Effect":"Deny","Action":["iam:*", "sts:*", "sdb:*"],"Resource":"*"}
    ]
}


IAM User Policy

The default IAM User Policy also needs to have the __BUCKET_NAME__ replaced. The bucket name here should match the bucket name used in the TokenVendingMachinePolicy.json object.

{
  "Statement": [
    {
        "Effect": "Allow",
        "Action": "sts:GetFederationToken",
        "Resource": "*"
    },
    {
        "Effect": "Allow",
        "Action": "iam:GetUser",
        "Resource": "*"
    },
    {
        "Effect": "Allow",
        "Action": ["s3:PutObject","s3:GetObject","s3:DeleteObject"],
        "Resource": "arn:aws:s3:::__BUCKET_NAME__/*"
    },
    {
        "Effect": "Allow",
        "Action": ["s3:ListBucket"],
        "Resource": "arn:aws:s3:::__BUCKET_NAME__"
    },
    {
        "Effect": "Allow",
        "Action": "sdb:*",
        "Resource": "*"
    }
  ]
}

If you used my_s3_bucket as the bucket name for the substitution, your would policy result in the following:

{
  "Statement": [
    {
        "Effect": "Allow",
        "Action": "sts:GetFederationToken",
        "Resource": "*"
    },
    {
        "Effect": "Allow",
        "Action": "iam:GetUser",
        "Resource": "*"
    },
    {
        "Effect": "Allow",
        "Action": ["s3:PutObject","s3:GetObject","s3:DeleteObject"],
        "Resource": "arn:aws:s3:::my_s3_bucket/*"
    },
    {
        "Effect": "Allow",
        "Action": ["s3:ListBucket"],
        "Resource": "arn:aws:s3:::my_s3_bucket"
    },
    {
        "Effect": "Allow",
        "Action": "sdb:*",
        "Resource": "*"
    }
  ]
}